/**
 * 
 */
package org.vsg.stock.core.indicator.coordinate.shape;

import org.vsg.common.biz.uid.IdGenerator;
import org.vsg.common.biz.uid.UnifiedIDProvider;
import org.vsg.stock.core.indicator.coordinate.CoefficientException;

/**
 * @author Bill vison
 *
 */
public abstract class AbstractLineEquation implements LineEquation {

	private Double coefficientA;
	
	private Double coefficientB;
	
	@Override
	public double getCoefficientA() {
		return coefficientA;
	}

	public void setCoefficientA(Double coefficientA) {
		this.coefficientA = coefficientA;
	}

	@Override
	public double getCoefficientB() {
		return coefficientB;
	}

	public void setCoefficientB(Double coefficientB) {
		this.coefficientB = coefficientB;
	}	
	
	// --- local variable ---
	private String instId;	
	
	public AbstractLineEquation() {
		UnifiedIDProvider idProvider = new IdGenerator ();
		instId = idProvider.getUid();
	}	
	
	/* (non-Javadoc)
	 * @see org.vsg.stock.core.indicator.coordinate.ShapeEquation#getInstId()
	 */
	@Override
	public String getInstId() {
		// TODO Auto-generated method stub
		return instId;
	}

	/* (non-Javadoc)
	 * @see org.vsg.stock.core.indicator.coordinate.ShapeEquation#getDescription()
	 */
	@Override
	public String getDescription() {
		StringBuffer desc = new StringBuffer();
		desc.append("Linear equations : ").append("");
		desc.append("ax + b = y ").append("\n");
		desc.append("Coefficient 'a' = [").append(coefficientA).append("] , ");
		desc.append("Coefficient 'b' = [").append(coefficientB).append("] , ");

		return desc.toString();
	}

	/* (non-Javadoc)
	 * @see org.vsg.stock.core.indicator.coordinate.LineEquation#testFormulaValue(double)
	 */
	@Override
	public double calculateFormulaValue(double x) throws CoefficientException{
		
		if (coefficientA == null || coefficientB == null) {
			throw new CoefficientException("Coefficient 'a' or 'b' must be not null! ");
		}
		
		double y = coefficientA * x + coefficientB;

		return y;
	}

}
